﻿using System;
using System.Reflection;
using Mbs.Collections;
using Mbs.Reflection;

namespace Mbs
{
    /// <summary>
    /// 
    /// </summary>
    public static partial class MbsEnvironment
    {
        
         public static readonly string Platform;
         public static readonly string SDK_Path;
         public static readonly string ApplicationPath;
         public static readonly string AddInPath;
         public static readonly string DataPath;
         public static readonly string ResourcePath;
         public static readonly string ProductName;
         public const string AddInExtensionName = ".AddIn";
         public const string AddInPathName = @"AddIns/";

         internal static readonly string PropertiesFile;

         static MbsEnvironment()
         {
             switch (IntPtr.Size)
             {
                 case 4: Platform = "Win32"; break;
                 case 8: Platform = "Win64"; break;
                 default: Platform = "Other"; break;
             }

            

             var fullPath = typeof(object).Assembly.Location;
             var fileName = System.IO.Path.GetFileName(fullPath);
             SDK_Path = fullPath.Replace(fileName, "");

             ApplicationPath = AppDomain.CurrentDomain.BaseDirectory;

             AddInPath = ApplicationPath + @"\AddIns\";

             DataPath = ApplicationPath + @"\Data\";

             PropertiesFile = DataPath + @"\Mbs.Properties.xml";

             ResourcePath = DataPath + @"\Resources\";

             var asm = Assembly.GetEntryAssembly();
             if (asm == null)
                 return;

             AssemblyProductAttribute attr = Assembly.GetEntryAssembly().GetAttribute<AssemblyProductAttribute>(false);
             if (attr != null)
                 ProductName = attr.Product;
         }


         public static string StringResource(this string resourceName)
         {
             return StringParser.Parse("${res:" + resourceName + "}");
         }
    }

    public static partial class MbsEnvironment
    {
        
        public class AddIn
        {
            public const string Name = "Name";
            public const string Author = "Author";
            public const string Copyright = "Copyright";
            public const string Url = "Url";
            public const string Roles = "Roles";
            public const string Enabled = "Enabled";
            public const string Description = "Description";
            public const string HideInManager = "HideInManager";

            public const string Runtime = "Runtime";
            public const string Resources = "Resources";

            public const string UI = "UI";
        }
    }
}
